package service;

import dao.AdminDao;
import dao.AdminDaoImpl;
import modle.Admin;
import modle.bo.AdminLoginBO;
import modle.bo.AdminSearchBO;
import modle.vo.AdminInfoVO;

import java.util.List;

/**
 * @Author: ZeYu
 * @Date: 2022/3/13 16:08
 */
public class AdminServiceImpl implements AdminService {

    private AdminDao adminDao=new AdminDaoImpl();

    @Override
    public int login(AdminLoginBO loginBO) {

        Admin admin = new Admin(null, loginBO.getEmail(), loginBO.getPwd(), null);

        return adminDao.login(admin);



    }

    @Override
    public List<AdminInfoVO> allAdmins() {
        //两种方式：1.select username as email,xxxx  from admin

        //select username xxxx from admin
        // select username xxx from admin-----Lsit<Admin>-------> List<AdminInfoVO>

        return adminDao.allAdmins(new Admin());
    }

    //如果都不输入的情况下那么该方法和全量查询的结果是一模一样的
    //email nickname
    //select * from admin where email like ?
    //select * from admin where nickname like ?
    //select * from admin
    //select * from admin where email like ? and nickname like ?
    @Override
    public List<AdminInfoVO> getSearchAdmins(AdminSearchBO adminSearchBO) {
        Admin admin = new Admin(null, adminSearchBO.getEmail(), null, adminSearchBO.getNickname());
        return adminDao.allAdmins(admin);

    }
}
